﻿using System.Windows;
using System.Windows.Controls;

namespace SSC.Views
{
    /// <summary>
    /// AddUserWindow.xaml 的交互逻辑
    /// </summary>
    public partial class AddUserWindow : Window
    {
        public string UserName { get; private set; }
        public string UserPassword { get; private set; }
        public string? UserBackup { get; private set; }
        public string? UserFace { get; private set; }
        public AddUserWindow()
        {
            InitializeComponent();
        }
        // 选择图像按钮的事件
        private void UploadImageButton_Click(object sender, RoutedEventArgs e)
        {
            var openFileDialog = new Microsoft.Win32.OpenFileDialog();
            openFileDialog.Filter = "Image Files|*.jpg;*.jpeg;*.png;";
            if (openFileDialog.ShowDialog() == true)
            {
                UserFace = openFileDialog.FileName; // 保存图像路径
            }
        }
        // 确认按钮的事件
        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            UserName = UserNameTextBox.Text;
            UserPassword = PasswordBox.Password;
            UserBackup = (UserBackupComboBox.SelectedItem as ComboBoxItem)?.Content.ToString(); // 获取备注的选择项

            // 数据验证
            if (string.IsNullOrWhiteSpace(UserName) || string.IsNullOrWhiteSpace(UserPassword))
            {
                MessageBox.Show("用户名和密码不能为空", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            DialogResult = true; // 表示确定添加
            Close();
        }

        // 取消按钮的事件
        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            DialogResult = false; // 取消添加
            Close();
        }
    }
}
